//
//  ViewController.m
//  坐标转换
//
//  Created by mafeng on 16/7/26.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIView *fatherView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.fatherView = [[UIView alloc] init];
    _fatherView.frame = CGRectMake(100, 100, 300, 300);
    _fatherView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_fatherView];
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    _button.frame = CGRectMake(20, 20, 100, 50);
    _button.backgroundColor = [UIColor yellowColor];
    [_button setTitle:@"点击" forState:UIControlStateNormal];
    [_fatherView addSubview:_button];
    [_button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)click {
    /**
     - (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;
     *  调用者是要转变rect的view的父视图, view是要转化到的视图, rect是要转变rect的view的rect
     * 当view为空时, 转化到window
     
     
     - (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;
     // fromview
     // 参数与上面那个函数相反
     */
    CGRect newRect = [_button.superview convertRect:_button.frame toView:self.view];
    NSLog(@"%@", NSStringFromCGRect(newRect));
    _button.frame = newRect;
    [self.view addSubview:self.button];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
